package cn.net.xinyi.xs.model {
	
	import cn.net.xinyi.xs.model.vo.PageVO;
	
	import mx.rpc.events.FaultEvent;
	import mx.rpc.events.ResultEvent;
	import mx.rpc.remoting.RemoteObject;
	
	import org.puremvc.as3.multicore.patterns.proxy.Proxy;

	public class LoadOrgansProxy extends Proxy {
		
		// Proxy name
		public static const NAME:String = 'LoadOrgansProxy';
		
		// Notification constants
		public static const LOAD_ORGANCOUNT_SUCCESS:String = 'loadOrganCountSuccess';
		public static const LOAD_ORGANS_SUCCESS:String = 'loadOrgansSuccess';
		public static const LOAD_ORGANS_FAILED:String  = 'loadOrgansFailed';
		
		// Variables
		private var organServiceRO:RemoteObject;
		
		public function LoadOrgansProxy() {
			super(NAME);
			organServiceRO = new RemoteObject();
			organServiceRO.destination = "organRemoteObject";
			
			organServiceRO.getOrganCount.addEventListener(ResultEvent.RESULT, onGetOrganCountResult);
			organServiceRO.getOrganCount.addEventListener(FaultEvent.FAULT, onFault);
			
			organServiceRO.getOrgans.addEventListener(ResultEvent.RESULT, onGetOrgansResult);
			organServiceRO.getOrgans.addEventListener(FaultEvent.FAULT, onFault);
		}
		
		public function loadOrganCount():void {
			organServiceRO.getOrganCount();
		}
		
		public function loadOrgans(pageVO:PageVO):void {
			organServiceRO.getOrgans(pageVO);
		}
		
		private function onGetOrganCountResult(event:ResultEvent):void {
			sendNotification(LOAD_ORGANCOUNT_SUCCESS, event.result);
		}
		
		private function onGetOrgansResult(event:ResultEvent):void {
			sendNotification(LOAD_ORGANS_SUCCESS, event.result);
		}
		
		private function onFault(event:FaultEvent):void {
			sendNotification(LOAD_ORGANS_FAILED, event.fault.faultString);
		}
		
	}
}